﻿using Framework.SqlDataAccess.Controller;
using Framework.SqlDataAccess.Model;
using System.Collections.Generic;
using System.Text;
using Kaysite.Model;

namespace Kaysite.Controller
{
    public abstract class KaysiteController<M> : ControllerBase<M>
        where M : KaysiteModel, new()
    {
        public KaysiteController() : this(null, null, false) { }
        public KaysiteController(M model, DALCBase parent, bool useTransaction) : base(model, parent, useTransaction) { }

        public override string FactoryKey { get { return "Kaysite"; } }
        protected override bool UseDinamicSaveQuery { get { return true; } }
    }

    public abstract class KaysiteLinkController<M> : ReadWriteControllerMultiPK<M, int, int>
        where M : ModelBaseMultiPK, new()
    {
        public KaysiteLinkController() : this(null, null, false) { }
        public KaysiteLinkController(M model, DALCBase parent, bool useTransaction) : base(model, parent, useTransaction) { }

        public override string FactoryKey { get { return "Kaysite"; } }
        protected override bool UseDinamicSaveQuery { get { return true; } }
    }

    public static class Extensions
    {
        public static string ToCommaSeparatedString(this List<object> list)
        {
            if (list == null || list.Count == 0)
                return string.Empty;

            var sb = new StringBuilder();

            foreach (object id in list)
                sb.Append(id).Append(",");

            return sb.ToString().TrimEnd(',');
        }
    }
}
